﻿using System;
using System.Collections.Generic;
using EnvDTE;
using EnvDTE80;


namespace VsTortoiseSVN.Commands
{
    public class OpenModifiedFile : CommandBase
    {
        private Dialogs.OpenModifiedDocumentDialog _dialog { get; set; }

        public OpenModifiedFile(DTE2 app, string id)
            : base(app, id)
        {
            _dialog = new VsTortoiseSVN.Dialogs.OpenModifiedDocumentDialog(app);
        }

        public override vsCommandStatus QueryStatus()
        {
            if (!Application.HasProject())
                return vsCommandStatus.vsCommandStatusSupported;

            return vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled;
        }

        public override bool Exec()
        {
            if (!Application.SaveDocuments())
            {
                LastError = CommandError.SaveDocumentsFailed;
                return false;
            }

            List<string> directoryNames = new List<string>();
            Application.Solution.GetDirectoryNames(directoryNames);
            _dialog.Scan(directoryNames);
            _dialog.ShowDialog();
            LastError = CommandError.Success;
            return true;
        }
    }
}
